package com.example.user.web;

import com.example.user.service.PhoneMsgService;
import com.example.user.service.PropertyService;
import com.example.user.service.RedisService;
import com.example.user.service.UserService;

import entity.ServerResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import pojo.Parking;
import pojo.User;
import pojo.Vehicle;
import vo.CommentVo;
import vo.LoginVo;
import vo.RegisterVo;
import vo.UserInfoVo;

import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Service;
import java.util.UUID;

/**
 * @BelongsProject: airparking
 * @BelongsPackage: com.example.user.web
 * @Author: huan
 * @CreateTime: 2020-08-13 11:45
 * @Description:
 */
@RestController
public class UserController {

    @Autowired
    private PhoneMsgService phoneMsgService;

    @Autowired
    private RedisService redisService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Autowired
    UserService userService;

    @Autowired
    PropertyService propertyService;

    /**
     * 用户注册
     * @param registerVo 注册信息
     * @return
     */
    @PostMapping("/userRegister")
    public ServerResponseBody registerUser(@RequestBody RegisterVo registerVo) {

        return userService.registerUser(registerVo);
    }

    /**
     * 发送注册验证码
     *
     * @return
     */
    @PostMapping("/sendPhoneCode")
    public ServerResponseBody sendPhoneCode(@RequestBody RegisterVo registerVo) {

        return ServerResponseBody.success(phoneMsgService.sendPhoneMsg(registerVo.getPhone()));
    }

    /**
     * 用户登录
     * @param loginVo   登录信息
     * @param response
     * @return
     */
    @PostMapping("/userLogin")
    public ServerResponseBody userLogin(@RequestBody LoginVo loginVo, HttpServletResponse response) {

        return userService.userLogin(loginVo,response);
    }

    /**
     * 获取用户信息
     * @param userId
     * @return
     */
    @GetMapping("/getUserInfo")
    public ServerResponseBody getUserInfo(@RequestHeader(value = "userId") String userId) {

        return userService.getUserInfo(userId);
    }

    /**
     * 得到所有物业信息
     * @return
     */
    @GetMapping("/getAllProperty")
    public ServerResponseBody getAllProperty() {

        return propertyService.getAllProperty();
    }

    /**
     * 得到用户详情信息
     * @param userId
     * @return
     */
    @GetMapping("/getUserDetailInfo")
    public ServerResponseBody getUserDetailInfo(@RequestHeader(value = "userId") String userId) {

        return userService.getUserDetailInfo(userId);
    }

    /**
     * 修改密码
     * @param userId
     * @param loginVo
     * @return
     */
    @PostMapping("/changePassword")
    public ServerResponseBody changePassword(@RequestHeader(value = "userId") String userId,@RequestBody LoginVo loginVo) {

        return userService.changePassword(userId,loginVo);
    }

    /**
     * 得到车辆信息
     * @param userId
     * @return
     */
    @GetMapping("/getUserVehicleInfo")
    public ServerResponseBody getUserVehicleInfo(@RequestHeader(value = "userId") String userId) {

        return userService.getUserVehicleInfo(userId);
    }

    /**
     * 得到车位用户评论信息
     * @param parking
     * @return
     */
    @PostMapping("/getParkingComment")
    public ServerResponseBody getParkingComment(@RequestBody Parking parking) {

        return userService.getParkingComment(parking.getParkingId());
    }

    /**
     * 得到评论的回复评论信息
     * @param commentVo
     * @return
     */
    @PostMapping("/getChildrenComment")
    public ServerResponseBody getChildrenComment(@RequestBody CommentVo commentVo) {

        return userService.getChildrenComment(commentVo.getCommentId());
    }

    /**
     * 增加，修改车辆信息
     * @param vehicle
     * @return
     */
    @PostMapping("/changeVehicleInfo")
    public ServerResponseBody changeVehicleInfo(@RequestBody Vehicle vehicle,@RequestHeader(value = "userId") String userId) {

        return userService.changeVehicleInfo(vehicle,userId);
    }

    /**
     * 修改用户详情信息
     * @param userInfoVo
     * @return
     */
    @PostMapping("/changeUserDetailInfo")
    public ServerResponseBody changeUserDetailInfo(@RequestBody UserInfoVo userInfoVo, @RequestHeader(value = "userId") String userId) {

        return userService.changeUserDetailInfo(userInfoVo,userId);
    }

    /**
     * 得到该用户未读的消息
     * @param userId
     * @return
     */
    @GetMapping("/getNoReadByUserId")
    public ServerResponseBody getNoReadByUserId(@RequestHeader(value = "userId") String userId) {

        return userService.getNoReadByUserId(userId);
    }

    /**
     * 已读消息，将该用户未读的消息全部修改为已读
     * @param userId
     * @return
     */
    @GetMapping("/updateCommentStatus")
    public ServerResponseBody updateCommentStatus(@RequestHeader(value = "userId") String userId) {

        return userService.updateCommentStatus(userId);
    }

    /**
     * 添加消息，回复消息
     * @param userId
     * @return
     */
    @PostMapping("/replyComment")
    public ServerResponseBody replyComment(@RequestBody CommentVo commentVo,@RequestHeader(value = "userId") String userId) {



        return userService.replyComment(commentVo,userId);
    }
}

